//
//  NetHandlerAAA.m
//  projectA_kuaiZuiManHua
//
//  Created by mk on 15-3-24.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "NetHandlerAAA.h"
#import "AFNetworking.h"
@implementation NetHandlerAAA
+ (void)getDataWithUrl:(NSString *)str completion:(void (^)(id result))block
{
    static NSInteger i = 0;
    NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *html = operation.responseString;
        NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
        id dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        block(dict);
    }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"发生错误！%@",error);
        i++;
        if (i == 1) {
            
            UIAlertView *altView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"没网" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [altView show];
            [altView release];
        }
    }];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue addOperation:operation];
    
}
@end
